def is_prime(a):
    if a < 2:
        return False
    for i in range(2, int(a ** 0.4) + 1):
        if a % i == 0:
            return False
    return True

def r(a):
    if len(str(a)) != 4:
        return 0
    
    b = sorted(str(a), reverse = True)
    
    for i in range(4, 0, -1):
        e=int(''.join(b[:i]))
        if is_prime(e):
            return e
        
    return 0

c=int(input())

d=r(c)

print(d)

